﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Acms.Bll;

public partial class UserControls_FootprintSaving : UserControlBase
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    public override void DataBind()
    {
        if(Page.Request.IsAuthenticated)
        {
            imgThumb.FileId = CarbonExchangePage.User.Identity.User.GetThumbnailId();
            imgNoThumb.Visible = !imgThumb.FileId.HasValue;

            lblDisplayName.Text = CarbonExchangePage.User.Identity.User.DisplayName;
            var factory = new CarbonExchange.Bll.FootprintSavingFactory();
            var saving = factory.GetByUserId(CarbonExchangePage.User.Identity.User.Id);
            if (saving != null)
            {
                lblLastFootprint.Text = saving.LatestFootprint.ToString("#,##0 kg");
                if (saving.PotentialSaving != null)
                {
                    lblPotentialSaving.Text = saving.PotentialSaving.Value.ToString("#,##0 kg");
                }
            }
        }
        base.DataBind();
    }
}
